"use strict";

const { Controller } = require("egg");
class MaterialController extends Controller {
  async queryList() {
    const body = this.ctx.request.body;

    const page = 1; // 当前页码
    const limit = 10; // 每页显示的记录数
    const offset = (page - 1) * limit; // 计算偏移量
    const res = await this.app.model.TMaterial.findAndCountAll({
      where: {
        // projectId: body.projectId,
      },
      limit,
      offset,
    });
    this.ctx.body = {
      data: res.rows,
      total: res.count,
      success: true,
    };
  }
  
  async save() {
    const data = this.ctx.request.body;
    if (data.id!==undefined) {
      const res = await this.app.model.TMaterial.update(data, {
        where: {
          id:data.id
        },
      });
    }else{
      const res = await this.app.model.TMaterial.create(data, {
        where: {},
      });
    }
  
    this.ctx.body = {
      code: 200,
    };
  }
  
  
}

module.exports = MaterialController;
